package command;

/**
 * @author chenyuan
 * @date 2020/10/29 15:02
 */

/**
 * 开灯方法，实现命令接口
 */
public class LightOnCommand implements Command{
    // 聚合 LightReceiver
    LightReceiver lightReceiver;

    // 通过构造器把 LightReceiver 实例传入
    public LightOnCommand(LightReceiver lightReceiver) {
        this.lightReceiver = lightReceiver;
    }

    @Override
    public void execute() {
        // 根据业务逻辑来选择这里应该执行 LightReceiver 中的哪一个方法
        // 调用 开方法
        lightReceiver.on();
    }

    @Override
    public void undo() {
        lightReceiver.off();
    }
}
